/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroProdutos.java
 *
 * Created on 13/10/2011, 11:03:56
 */
package frames.Cadastro;

import classes.Categoria;
import classes.Distribuidor;
import logicaBancoDeDados.ConectaProdutos;
import classes.Produto;
import classes.Vendedor;
import frames.Gerenciamento.*;
import frames.Menus.*;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.plaf.basic.BasicComboBoxUI.ComboBoxLayoutManager;
import logicaBancoDeDados.ConectaCategorias;
import logicaBancoDeDados.ConectaDistribuidor;
import logicaBancoDeDados.ConectaVendedores;

/**
 *
 * @author User
 */
public class CadastroProdutos extends javax.swing.JFrame {


    public CadastroProdutos() {
        initComponents();
    }
    ConectaVendedores conectaVendedores = new ConectaVendedores();
    ConectaProdutos conectaProdutos = new ConectaProdutos();
    ConectaDistribuidor conectaDistribuidor = new ConectaDistribuidor();
    ConectaCategorias conectaCategorias = new ConectaCategorias();
    DefaultComboBoxModel modeloComboCategoria = new DefaultComboBoxModel();
    DefaultComboBoxModel modeloComboVendedor = new DefaultComboBoxModel();
    DefaultComboBoxModel modeloComboDistribuidor = new DefaultComboBoxModel();
    Produto produto = new Produto();

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jFormattedTextField4 = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        lbProduto = new javax.swing.JLabel();
        lbBarCode = new javax.swing.JLabel();
        lbQuant = new javax.swing.JLabel();
        tfProduto = new javax.swing.JTextField();
        lbMessage = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        carregaCbCategoria(conectaCategorias.listaTodasCategorias());
        cbCategoria = new javax.swing.JComboBox();
        lbCompra = new javax.swing.JLabel();
        lbVenda = new javax.swing.JLabel();
        ftfCompra = new javax.swing.JFormattedTextField();
        ftfVenda = new javax.swing.JFormattedTextField();
        tfQuant = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        ftfData = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cbDistribuidor = new javax.swing.JComboBox();
        carregaCbDistribuidor(conectaDistribuidor.listAll());
        cbDistribuidor.setSelectedIndex(-1);
        cbVendedor = new javax.swing.JComboBox();
        carregaCbVendedor(conectaVendedores.listAll());
        tfBarCode = new javax.swing.JFormattedTextField();
        jPanel2 = new javax.swing.JPanel();
        btSalvar = new javax.swing.JButton();
        btLimpar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        jMenuBar2 = new javax.swing.JMenuBar();
        menuArquivo = new javax.swing.JMenu();
        itemMenuPrincipal = new javax.swing.JMenuItem();
        itemMenuCadastro = new javax.swing.JMenuItem();
        itemMenuGerenciamento = new javax.swing.JMenuItem();
        itemFechar = new javax.swing.JMenuItem();
        menuCadastro = new javax.swing.JMenu();
        itemCadastraDistribuidores = new javax.swing.JMenuItem();
        itemCadastraVendedores = new javax.swing.JMenuItem();
        itemCadastraProdutos = new javax.swing.JMenuItem();
        itemCadastraSaidaEstoque = new javax.swing.JMenuItem();
        menuGerenciamento = new javax.swing.JMenu();
        itemGerenciaCategorias = new javax.swing.JMenuItem();
        itemGerenciaDistribuidores = new javax.swing.JMenuItem();
        itemGerenciaGarantias = new javax.swing.JMenuItem();
        itemGerenciaProdutos = new javax.swing.JMenuItem();
        itemGerenciaVendedores = new javax.swing.JMenuItem();
        menuAjuda = new javax.swing.JMenu();
        itemSobre = new javax.swing.JMenuItem();

        jFormattedTextField1.setText("jFormattedTextField1");

        jTextField3.setText("jTextField3");

        jTextField2.setText("jTextField2");

        jLabel3.setText("jLabel3");

        jLabel5.setText("jLabel5");

        jFormattedTextField4.setText("jFormattedTextField4");

        jLabel7.setText("jLabel7");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Cadastro de Produto");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                Confirma(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Cadastra"));

        lbProduto.setText("Produto:");

        lbBarCode.setText("Código de Barra:");

        lbQuant.setText("Quantidade:");

        tfProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfProdutoActionPerformed(evt);
            }
        });
        tfProduto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corProduto(evt);
            }
        });

        jLabel1.setText("Categoria");

        cbCategoria.setModel(modeloComboCategoria);
        cbCategoria.setSelectedIndex(-1);
        cbCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCategoriaActionPerformed(evt);
            }
        });
        cbCategoria.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corCategoria(evt);
            }
        });

        lbCompra.setText("Valor de compra: ");

        lbVenda.setText("Valor de venda: ");

        ftfCompra.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        ftfCompra.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                ftfCompra(evt);
            }
        });

        ftfVenda.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        ftfVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ftfVendaActionPerformed(evt);
            }
        });
        ftfVenda.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corVenda(evt);
            }
        });

        tfQuant.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corQuantidade(evt);
            }
        });

        jLabel2.setText("Data entrada:");

        try {
            ftfData.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("**/**/****")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        ftfData.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corData(evt);
            }
        });

        jLabel4.setText("Distribuidor:");

        jLabel6.setText("Vendedor:");

        cbDistribuidor.setModel(modeloComboDistribuidor);
        cbDistribuidor.setSelectedIndex(-1);
        cbDistribuidor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                listaVendedor(evt);
            }
        });
        cbDistribuidor.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corDistribuidor(evt);
            }
        });

        cbVendedor.setModel(modeloComboVendedor);
        cbVendedor.setSelectedIndex(-1);
        cbVendedor.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corVendedor(evt);
            }
        });

        try {
            tfBarCode.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("*************")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfBarCode.setText(null);
        tfBarCode.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                corBarCode(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 391, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbVenda)
                            .addComponent(lbCompra)
                            .addComponent(lbBarCode)
                            .addComponent(lbProduto)
                            .addComponent(lbQuant)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cbDistribuidor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(ftfData, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel6))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(cbCategoria, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(cbVendedor, javax.swing.GroupLayout.Alignment.LEADING, 0, 122, Short.MAX_VALUE)))
                            .addComponent(tfProduto, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                            .addComponent(tfQuant, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                            .addComponent(ftfCompra, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                            .addComponent(ftfVenda, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                            .addComponent(tfBarCode, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbProduto)
                    .addComponent(tfProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbBarCode)
                    .addComponent(tfBarCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbQuant)
                    .addComponent(tfQuant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCompra)
                    .addComponent(ftfCompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbVenda)
                    .addComponent(ftfVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cbDistribuidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(cbVendedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(ftfData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(cbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        btLimpar.setText("Limpar");
        btLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparActionPerformed(evt);
            }
        });

        btCancelar.setText("Voltar");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btSalvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btLimpar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btCancelar)
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancelar, btLimpar, btSalvar});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btLimpar)
                    .addComponent(btCancelar)
                    .addComponent(btSalvar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        menuArquivo.setText("Menu");

        itemMenuPrincipal.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.SHIFT_MASK));
        itemMenuPrincipal.setText("Menu Principal");
        itemMenuPrincipal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuPrincipalActionPerformed(evt);
            }
        });
        menuArquivo.add(itemMenuPrincipal);

        itemMenuCadastro.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK));
        itemMenuCadastro.setText("Menu Cadastro");
        itemMenuCadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuCadastroActionPerformed(evt);
            }
        });
        menuArquivo.add(itemMenuCadastro);

        itemMenuGerenciamento.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        itemMenuGerenciamento.setText("Menu Gerenciamento");
        itemMenuGerenciamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuGerenciamentoActionPerformed(evt);
            }
        });
        menuArquivo.add(itemMenuGerenciamento);

        itemFechar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        itemFechar.setText("Fechar");
        itemFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemFecharActionPerformed(evt);
            }
        });
        menuArquivo.add(itemFechar);

        jMenuBar2.add(menuArquivo);

        menuCadastro.setText("Cadastro");

        itemCadastraDistribuidores.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        itemCadastraDistribuidores.setText("Distribuidores");
        itemCadastraDistribuidores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCadastraDistribuidoresActionPerformed(evt);
            }
        });
        menuCadastro.add(itemCadastraDistribuidores);

        itemCadastraVendedores.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SPACE, java.awt.event.InputEvent.CTRL_MASK));
        itemCadastraVendedores.setText("Vendedores");
        itemCadastraVendedores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCadastraVendedoresActionPerformed(evt);
            }
        });
        menuCadastro.add(itemCadastraVendedores);

        itemCadastraProdutos.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0));
        itemCadastraProdutos.setText("Produtos");
        itemCadastraProdutos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCadastraProdutosActionPerformed(evt);
            }
        });
        menuCadastro.add(itemCadastraProdutos);

        itemCadastraSaidaEstoque.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        itemCadastraSaidaEstoque.setText("Saida de Estoque");
        itemCadastraSaidaEstoque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCadastraSaidaEstoqueActionPerformed(evt);
            }
        });
        menuCadastro.add(itemCadastraSaidaEstoque);

        jMenuBar2.add(menuCadastro);

        menuGerenciamento.setText("Gerenciamento");

        itemGerenciaCategorias.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemGerenciaCategorias.setText("Categorias");
        itemGerenciaCategorias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGerenciaCategoriasActionPerformed(evt);
            }
        });
        menuGerenciamento.add(itemGerenciaCategorias);

        itemGerenciaDistribuidores.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemGerenciaDistribuidores.setText("Distribuidores");
        itemGerenciaDistribuidores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGerenciaDistribuidoresActionPerformed(evt);
            }
        });
        menuGerenciamento.add(itemGerenciaDistribuidores);

        itemGerenciaGarantias.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemGerenciaGarantias.setText("Garantias");
        itemGerenciaGarantias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGerenciaGarantiasActionPerformed(evt);
            }
        });
        menuGerenciamento.add(itemGerenciaGarantias);

        itemGerenciaProdutos.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemGerenciaProdutos.setText("Produtos");
        itemGerenciaProdutos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGerenciaProdutosActionPerformed(evt);
            }
        });
        menuGerenciamento.add(itemGerenciaProdutos);

        itemGerenciaVendedores.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        itemGerenciaVendedores.setText("Vendedores");
        itemGerenciaVendedores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemGerenciaVendedoresActionPerformed(evt);
            }
        });
        menuGerenciamento.add(itemGerenciaVendedores);

        jMenuBar2.add(menuGerenciamento);

        menuAjuda.setText("Ajuda");

        itemSobre.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F12, 0));
        itemSobre.setText("Sobre");
        itemSobre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemSobreActionPerformed(evt);
            }
        });
        menuAjuda.add(itemSobre);

        jMenuBar2.add(menuAjuda);

        setJMenuBar(jMenuBar2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(212, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        if(confirmaCampos() == true){
            produto.setNomeProduto(tfProduto.getText());
            produto.setBarCode(tfBarCode.getText());
            produto.setCategoria(cbCategoria.getSelectedItem().toString());
            produto.setCompra(Float.parseFloat(ftfCompra.getText().replace(",",".")));
            produto.setDataCompra(ftfData.getText());
            produto.setDistribuidor(cbDistribuidor.getSelectedItem().toString());
            produto.setQuantidade(Integer.parseInt(tfQuant.getText()));
            produto.setVenda(Float.parseFloat(ftfVenda.getText().replace(",",".")));
            produto.setVendedor(cbVendedor.getSelectedItem().toString());
            produto.setLogEntrada("Produto: "+tfProduto.getText()+" Quantidade comprada: "+tfQuant.getText()+" Vendedor: "+cbVendedor.getSelectedItem().toString()+" Data de compra: "+ftfData.getText());
            lbMessage.setText(conectaProdutos.insere(produto));
            
        }

    }//GEN-LAST:event_btSalvarActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null, "Deseja finalizar essa operação?", "Finalizar", JOptionPane.YES_NO_OPTION);
        //sim = 0, nao = 1  
        if (resposta == 0) {
            new MenuPrincipal().setVisible(true);
            dispose();
        }

    }//GEN-LAST:event_btCancelarActionPerformed

    private void btLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparActionPerformed
        limparTudo();
    }//GEN-LAST:event_btLimparActionPerformed

    private void cbCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCategoriaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbCategoriaActionPerformed

    private void ftfVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ftfVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ftfVendaActionPerformed

    private void Confirma(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_Confirma
        int resposta = JOptionPane.showConfirmDialog(null, "Deseja finalizar essa operação?", "Finalizar", JOptionPane.YES_NO_OPTION);
        //sim = 0, nao = 1  
        if (resposta == 0) {
            System.exit(0);
        }
    }//GEN-LAST:event_Confirma

    private void tfProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfProdutoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfProdutoActionPerformed

    private void itemMenuPrincipalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemMenuPrincipalActionPerformed
        new MenuPrincipal().setVisible(true);
        dispose();
    }//GEN-LAST:event_itemMenuPrincipalActionPerformed

    private void itemMenuCadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemMenuCadastroActionPerformed
        new MenuCadastro().setVisible(true);
    }//GEN-LAST:event_itemMenuCadastroActionPerformed

    private void itemMenuGerenciamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemMenuGerenciamentoActionPerformed
        new MenuGerenciamento().setVisible(true);
    }//GEN-LAST:event_itemMenuGerenciamentoActionPerformed

    private void itemFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemFecharActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null, "Deseja realmente encerrar o programa", "Confirmação", JOptionPane.YES_NO_OPTION);
        if (resposta == 0) {
            System.exit(0);
            dispose();
        }
    }//GEN-LAST:event_itemFecharActionPerformed

    private void itemCadastraDistribuidoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCadastraDistribuidoresActionPerformed
        new CadastroDistribuidores().setVisible(true);
    }//GEN-LAST:event_itemCadastraDistribuidoresActionPerformed

    private void itemCadastraVendedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCadastraVendedoresActionPerformed
        new CadastroVendedores().setVisible(true);
    }//GEN-LAST:event_itemCadastraVendedoresActionPerformed

    private void itemCadastraProdutosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCadastraProdutosActionPerformed
        new CadastroProdutos().setVisible(true);
    }//GEN-LAST:event_itemCadastraProdutosActionPerformed

    private void itemCadastraSaidaEstoqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCadastraSaidaEstoqueActionPerformed
        new CadastroSaidasEstoque().setVisible(true);
    }//GEN-LAST:event_itemCadastraSaidaEstoqueActionPerformed

    private void itemGerenciaCategoriasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGerenciaCategoriasActionPerformed
        new GerenciaCategorias().setVisible(true);
    }//GEN-LAST:event_itemGerenciaCategoriasActionPerformed

    private void itemGerenciaDistribuidoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGerenciaDistribuidoresActionPerformed
        new GerenciaDistribuidores().setVisible(true);

    }//GEN-LAST:event_itemGerenciaDistribuidoresActionPerformed

    private void itemGerenciaGarantiasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGerenciaGarantiasActionPerformed
        new GerenciaGarantias().setVisible(true);

    }//GEN-LAST:event_itemGerenciaGarantiasActionPerformed

    private void itemGerenciaProdutosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGerenciaProdutosActionPerformed
        new GerenciaProdutos().setVisible(true);
    }//GEN-LAST:event_itemGerenciaProdutosActionPerformed

    private void itemGerenciaVendedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemGerenciaVendedoresActionPerformed
        new GerenciaVendedores().setVisible(true);
    }//GEN-LAST:event_itemGerenciaVendedoresActionPerformed

    private void itemSobreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemSobreActionPerformed
        JOptionPane.showMessageDialog(null, "Programa criado por Danilo Vicente Diorio \n\n\n Sob Licença GPL.");
    }//GEN-LAST:event_itemSobreActionPerformed

    private void listaVendedor(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_listaVendedor
        ArrayList<Vendedor> listaVendedores = new ArrayList<Vendedor>();
        Vendedor vend1 = new Vendedor();
        if (cbDistribuidor.getSelectedIndex() != -1) {
            vend1.setEmpresa(cbDistribuidor.getSelectedItem().toString());
            listaVendedores = conectaVendedores.listVendedorDistribuidor("%" + cbDistribuidor.getSelectedItem().toString() + "%");
            carregaCbVendedor(listaVendedores);
        }

    }//GEN-LAST:event_listaVendedor

    private void corProduto(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corProduto
        tfProduto.setBackground(Color.WHITE);
    }//GEN-LAST:event_corProduto

    private void corBarCode(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corBarCode
        tfBarCode.setBackground(Color.WHITE);
    }//GEN-LAST:event_corBarCode

    private void corQuantidade(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corQuantidade
        tfQuant.setBackground(Color.WHITE);
    }//GEN-LAST:event_corQuantidade

    private void ftfCompra(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ftfCompra
        ftfCompra.setBackground(Color.WHITE);
    }//GEN-LAST:event_ftfCompra

    private void corVenda(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corVenda
        ftfVenda.setBackground(Color.WHITE);
    }//GEN-LAST:event_corVenda

    private void corDistribuidor(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corDistribuidor
        cbDistribuidor.setBackground(Color.getColor("214,217,223"));
    }//GEN-LAST:event_corDistribuidor

    private void corVendedor(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corVendedor
        cbVendedor.setBackground(Color.getColor("214,217,223"));
    }//GEN-LAST:event_corVendedor

    private void corCategoria(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corCategoria
        cbCategoria.setBackground(Color.getColor("214,217,223"));
    }//GEN-LAST:event_corCategoria

    private void corData(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_corData
        ftfData.setBackground(Color.WHITE);
    }//GEN-LAST:event_corData

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroProdutos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new CadastroProdutos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btLimpar;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cbCategoria;
    private javax.swing.JComboBox cbDistribuidor;
    private javax.swing.JComboBox cbVendedor;
    private javax.swing.JFormattedTextField ftfCompra;
    private javax.swing.JFormattedTextField ftfData;
    private javax.swing.JFormattedTextField ftfVenda;
    private javax.swing.JMenuItem itemCadastraDistribuidores;
    private javax.swing.JMenuItem itemCadastraProdutos;
    private javax.swing.JMenuItem itemCadastraSaidaEstoque;
    private javax.swing.JMenuItem itemCadastraVendedores;
    private javax.swing.JMenuItem itemFechar;
    private javax.swing.JMenuItem itemGerenciaCategorias;
    private javax.swing.JMenuItem itemGerenciaDistribuidores;
    private javax.swing.JMenuItem itemGerenciaGarantias;
    private javax.swing.JMenuItem itemGerenciaProdutos;
    private javax.swing.JMenuItem itemGerenciaVendedores;
    private javax.swing.JMenuItem itemMenuCadastro;
    private javax.swing.JMenuItem itemMenuGerenciamento;
    private javax.swing.JMenuItem itemMenuPrincipal;
    private javax.swing.JMenuItem itemSobre;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JFormattedTextField jFormattedTextField4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JLabel lbBarCode;
    private javax.swing.JLabel lbCompra;
    private javax.swing.JLabel lbMessage;
    private javax.swing.JLabel lbProduto;
    private javax.swing.JLabel lbQuant;
    private javax.swing.JLabel lbVenda;
    private javax.swing.JMenu menuAjuda;
    private javax.swing.JMenu menuArquivo;
    private javax.swing.JMenu menuCadastro;
    private javax.swing.JMenu menuGerenciamento;
    private javax.swing.JFormattedTextField tfBarCode;
    private javax.swing.JTextField tfProduto;
    private javax.swing.JTextField tfQuant;
    // End of variables declaration//GEN-END:variables

    private void carregaCbCategoria(List<Categoria> listaCategoria) {
        if (listaCategoria.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Sem categorias cadastras");
        } else {
            modeloComboCategoria.removeAllElements();
            for (int i = 0; i < listaCategoria.size(); i++) {
                modeloComboCategoria.addElement(listaCategoria.get(i).getCategoria());
            }
        }

    }

    private boolean confirmaCampos() {
        boolean cond = true;
        int dia = 0, mes = 0, ano = 0, quant = 0;
        float valorCompra = 0, valorVenda = 0;
        String produto, barCode, distribuidor, vendedor, categoria, erro = "";
        try {
            if (tfBarCode.getText().isEmpty() || tfProduto.getText().isEmpty() || tfQuant.getText().isEmpty() || ftfCompra.getText().isEmpty() || ftfData.getText().isEmpty() || ftfVenda.getText().isEmpty() || cbCategoria.getSelectedIndex() == -1 || cbDistribuidor.getSelectedIndex() == -1 || cbVendedor.getSelectedIndex() == -1) {

                if (tfBarCode.getText().equals("             ")) {
                    tfBarCode.setBackground(Color.red);
                }
                if (tfProduto.getText().isEmpty()) {
                    tfProduto.setBackground(Color.red);
                }
                if (tfQuant.getText().isEmpty()) {
                    tfQuant.setBackground(Color.red);
                }
                if (ftfCompra.getText().isEmpty()) {
                    ftfCompra.setBackground(Color.red);
                }
                if (ftfData.getText().equals("  /  /    ")) {
                    ftfData.setBackground(Color.red);
                }
                if (ftfVenda.getText().isEmpty()) {
                    ftfVenda.setBackground(Color.red);
                }
                if (cbCategoria.getSelectedIndex() == -1) {
                    cbCategoria.setBackground(Color.red);
                }
                if (cbDistribuidor.getSelectedIndex() == -1) {
                    cbDistribuidor.setBackground(Color.red);
                }
                if (cbVendedor.getSelectedIndex() == -1) {
                    cbVendedor.setBackground(Color.red);
                }
                erro += "Favor cadastrar os campos em vermelho. ";
                cond = false;
            } else {
                barCode = tfBarCode.getText();
                quant = Integer.parseInt(tfQuant.getText());
                dia = Integer.parseInt(ftfData.getText().substring(0, 2));
                mes = Integer.parseInt(ftfData.getText().substring(3, 5));
                ano = Integer.parseInt(ftfData.getText().substring(6));
                valorCompra = Float.parseFloat(ftfCompra.getText().replace(",", "."));
                valorVenda = Float.parseFloat(ftfVenda.getText().replace(",", "."));
                categoria = cbCategoria.getSelectedItem().toString();
                distribuidor = cbDistribuidor.getSelectedItem().toString();
                vendedor = cbVendedor.getSelectedItem().toString();
                produto = tfProduto.getText();

                //verifica data
                if (dia > 31 || dia < 0 || mes > 12 || mes < 0 || ano < 0 || ano > 9999) {
                    ftfData.setBackground(Color.red);
                    erro += "Data inválida. ";
                    cond = false;
                } else {
                    if (dia > 30 && mes == 4 || dia > 30 && mes == 6 || dia > 30 && mes == 9 || dia > 30 && mes == 11) {
                        ftfData.setBackground(Color.red);
                        erro += "Esse mês só tem 30 dias";
                        cond = false;
                    } //meses 30 dias
                    if (dia > 29 && mes == 2) {
                        ftfData.setBackground(Color.red);
                        erro += "Fevereiro não tem mais de 29 dias";
                        cond = false;
                    } //fevereiro
                    if (dia == 29 && mes == 2 && ano % 4 != 0 || ano % 100 == 0 && ano % 400 != 0) {
                        ftfData.setBackground(Color.red);
                        erro += "Ano não é bissexto";
                        cond = false;
                    } //bissexto
                } // final do verifica data
                if (barCode.matches("^[0-9]*$") == false) {
                    tfBarCode.setBackground(Color.red);
                    erro += "Código de barra invalido";
                    cond = false;
                }
                if (quant <= 0) {
                    tfQuant.setBackground(Color.red);
                    erro += "Quantidade inválida";
                    cond = false;
                }
                if (valorCompra <= 0) {
                    ftfCompra.setBackground(Color.red);
                    erro += "Valor de compra inválido";
                    cond = false;
                }
                if (valorVenda <= 0) {
                    ftfVenda.setBackground(Color.red);
                    erro += "Valor de venda inválido";
                    cond = false;
                }
            }
        } catch (NumberFormatException e) {
            if (dia == 0 || mes == 0 || ano == 0) {
                ftfData.setBackground(Color.red);
                erro += "Data não foi preenchida corretamente. ";
                cond = false;
            }

            if (valorCompra == 0) {
                ftfCompra.setBackground(Color.red);
                erro += "Valor de compra inválido ";
                cond = false;

            }

            if (valorVenda == 0) {
                ftfVenda.setBackground(Color.red);
                erro += "Valor de venda inválido";
                cond = false;
            }

        }

        lbMessage.setText(erro);
        return cond;
    }

    private void carregaCbDistribuidor(List<Distribuidor> listaDistribuidor) {
        if (listaDistribuidor.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Sem Distribuidoras cadastras");
        } else {
            modeloComboDistribuidor.removeAllElements();
            for (int i = 0; i < listaDistribuidor.size(); i++) {
                modeloComboDistribuidor.addElement(listaDistribuidor.get(i).getDistribuidor());
            }
        }
    }

    private void carregaCbVendedor(List<Vendedor> listaVendedor) {
        if (listaVendedor.isEmpty()) {
            modeloComboVendedor.removeAllElements();
        } else {
            modeloComboVendedor.removeAllElements();
            for (int i = 0; i < listaVendedor.size(); i++) {
                modeloComboVendedor.addElement(listaVendedor.get(i).getNome());
            }
        }
        cbVendedor.setSelectedIndex(-1);
    }

    private void limparTudo() {
        tfBarCode.setText(null);
        tfQuant.setText(null);
        tfProduto.setText(null);
        lbMessage.setText(null);
        ftfCompra.setText(null);
        ftfVenda.setText(null);
        ftfData.setText(null);
        cbCategoria.setSelectedIndex(-1);
        carregaCbVendedor(conectaVendedores.listAll());
        cbDistribuidor.setSelectedIndex(-1);
        tfBarCode.setBackground(Color.WHITE);
        tfQuant.setBackground(Color.WHITE);
        tfProduto.setBackground(Color.WHITE);
        lbMessage.setBackground(Color.WHITE);
        ftfCompra.setBackground(Color.WHITE);
        ftfVenda.setBackground(Color.WHITE);
        ftfData.setBackground(Color.WHITE);
        cbCategoria.setBackground(Color.getColor("214,217,223"));
        cbDistribuidor.setBackground(Color.getColor("214,217,223"));
        cbVendedor.setBackground(Color.getColor("214,217,223"));
    }
}
